package com.mrzhu.demo;



/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2021/11/15
 * \* Time: 18:35
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */

//class Animal {
//    public String name;
//    public Animal(String name) {
//        this.name = name;
//    }
//    public void eat(String food) {
//        System.out.println(this.name + "正在吃" + food);
//    }
//}
//class Bird extends Animal {
//    public Bird(String name) {
//        super(name);
//    }
//    public void fly() {
//        System.out.println(this.name + "正在飞 ");
//    }
//}
//public class TestDemo {
//    //3.方法返回
//    public static Animal func() {
//        return new Bird("圆圆");
//    }
//
//    public static void main(String[] args) {
//        Animal animal = func();
//        animal.eat("虫子");
//    }
//
//    //2.方法传参
//    public static void func(Animal bird) {
//        bird.eat("虫子");
//    }
//    public static void main2(String[] args) {
//        Bird bird = new Bird("圆圆");
//        func(bird);
//    }
//
//    //1.直接赋值
//    public static void main1(String[] args) {
//        Animal bird = new Bird("圆圆");
//        bird.eat("虫子");
//
//    }
//}


// Animal.java
//class Animal {
//    protected String name;
//    public Animal(String name) {
//        this.name = name;
//    }
//    public void eat(String food) {
//        System.out.println("我是一只小动物");
//        System.out.println(this.name + "正在吃" + food);
//    }
//}
//// Bird.java
//class Bird extends Animal {
//    public Bird(String name) {
//        super(name);
//    }
//    public void eat(String food) {
//        System.out.println("我是一只小鸟");
//        System.out.println(this.name + "正在吃" + food);
//    }
//}
//// Test.java
//public class TestDemo {
//    public static void main(String[] args) {
//        Bird bird = (Bird)animal;
//        bird.fly();
//    }
//}


// Animal.java
class Animal {
    protected String name;
    public Animal(String name) {
        this.name = name;
    }
    public void eat(String food) {
        System.out.println("我是一只小动物");
        System.out.println(this.name + "正在吃" + food);
    }
}
// Bird.java
class Bird extends Animal {
    public Bird(String name) {
        super(name);
    }
    public void eat(String food) {
        System.out.println("我是一只小鸟");
        System.out.println(this.name + "正在吃" + food);
    }

    public void fly() {
        System.out.println(this.name + "正在飞");
    }
}

public class TestDemo{
    public static void main(String[] args) {
        Animal animal = new Bird("圆圆");
        if(animal instanceof Bird){
            Bird bird = (Bird)animal;
            bird.fly();
        }else {
            System.out.println("不合法");
        }

    }
}